#!/bin/bash
#chmod +x nagcent
#Nagcent Install Script version 0.2
set -e
apt-get -f install -y mailutils
apt-get -f install -y build-essential
apt-get -f install -y sudo
apt-get -f install -y apache2 apache2-mpm-prefork
apt-get -f install -y php5 php5-mysql php-pear php5-ldap php5-snmp php5-gd
apt-get -f install -y mysql-server libmysqlclient15-dev
apt-get -f install -y rrdtool librrds-perl
apt-get -f install -y libconfig-inifiles-perl libcrypt-des-perl libdigest-hmac-perl libdigest-sha1-perl libgd-gd2-perl
apt-get -f install -y snmp snmpd libnet-snmp-perl libsnmp-perl
apt-get -f install -y libgd2-xpm libgd2-xpm-dev libpng12-dev
/usr/sbin/useradd -m nagios
passwd nagios
/usr/sbin/groupadd nagcmd
/usr/sbin/usermod -G nagios,nagcmd nagios
/usr/sbin/usermod -G nagios,nagcmd www-data
#
#Install Nagios
#
cd /usr/local/src/
wget http://download.tech-max.fr/nagios/nagios-3.2.3.tar.gz
tar xvzf nagios-3.2.3.tar.gz
cd nagios-3.2.3/
./configure --prefix=/usr/local/nagios --with-command-group=nagcmd --enable-nanosleep --enable-event-broker
make all
make install
make install-init
make install-commandmode
make install-config
#
# Install and activate Nagios web interface
#
cd /usr/local/src/nagios-3.2.3/
make install-webconf
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
/etc/init.d/apache2 reload
#
#Install Nagios plugins
#
cd /usr/local/src/
wget http://download.tech-max.fr/nagios/nagios-plugins-1.4.15.tar.gz
tar xvzf nagios-plugins-1.4.15.tar.gz
cd nagios-plugins-1.4.15/
./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl=/usr/bin/openssl
make
make install
#
#Install NDO
#
apt-get -f install -y subversion
cd /usr/local/src/
wget http://download.tech-max.fr/nagios/ndoutils-1.4b9.tar.gz
tar xvzf ndoutils-1.4b9.tar.gz
cd ndoutils-1.4b9
wget http://download.tech-max.fr/nagios/ndoutils1.4b9_light.patch
patch -p1 -N < ndoutils1.4b9_light.patch
./configure --prefix=/usr/local/nagios/ --enable-mysql --disable-pgsql \
   --with-ndo2db-user=nagios --with-ndo2db-group=nagios
make
cp ./src/ndomod-3x.o /usr/local/nagios/bin/ndomod.o
cp ./src/ndo2db-3x /usr/local/nagios/bin/ndo2db
cp ./config/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg
cp ./config/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg
chmod 775 /usr/local/nagios/bin/ndo*
chown nagios:nagios /usr/local/nagios/bin/ndo*
cp ./daemon-init /etc/init.d/ndo2db
update-rc.d ndo2db defaults
chmod +x /etc/init.d/ndo2db
#
#Install Centreon
#
cd /usr/local/src/
wget http://download.tech-max.fr/nagios/centreon-2.1.10.tar.gz
tar xvzf centreon-2.1.10.tar.gz
cd centreon-2.1.10/
export PATH="$PATH:/usr/local/nagios/bin/"
./install.sh -i
/etc/init.d/apache2 reload
#
#Langue Centreon
#
apt-get -f install -y gettext
mkdir /usr/local/centreon/www/locale/fr_FR.UTF-8/
mkdir /usr/local/centreon/www/locale/fr_FR.UTF-8/LC_MESSAGES/
cd /usr/local/src/
wget http://download.tech-max.fr/nagios/centreon-2.1-fr_FR-1.tgz
tar xvzf centreon-2.1-fr_FR-1.tgz
cd centreon-2.1-fr_FR-1.1/LC_MESSAGES
cp messages.mo /usr/local/centreon/www/locale/fr_FR.UTF-8/LC_MESSAGES/messages.mo
read -p "Se connecter à http://Ip/centreon, suivre les étapes de configuration de l'interface Centreon et à la fin appuyer sur une touche pour finaliser..."
cd /etc/init.d
update-rc.d nagios defaults
/etc/init.d/ndo2db start
/etc/init.d/nagios start
tail -f /usr/local/nagios/var/nagios.log | grep ndomod